﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CNDM.UserControls.List
{
    public partial class ucListFocus : System.Web.UI.UserControl
    {
        private int cat_id = 0;
        private int top = 5;
        private string cat_displayurl = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["cat_displayurl"] != null && Request.QueryString["cat_displayurl"].ToString() != "")
            {
                cat_displayurl = Request.QueryString["cat_displayurl"].ToString();
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dtCat = new DataTable();
            dtCat = BO.Category.CategoryData.Get_Category_by_CatUrl(cat_displayurl);
            if (dtCat != null && dtCat.Rows.Count>0)
            {
                cat_id = Convert.ToInt32(dtCat.Rows[0]["cat_id"]);
                
            }

            DataTable dt = new DataTable();
            dt = BO.News.NewsData.Get_NoiBatChuyenMuc(cat_id, top);
            repFocus.DataSource = dt;
            repFocus.DataBind();
        }

        protected void repFocus_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Image imgNews = (Image)e.Item.FindControl("imgNews");
                if (DataBinder.Eval(e.Item.DataItem, "News_Image").ToString().Trim() == "")
                {
                    imgNews.Visible = false;
                }
                else
                {
                    imgNews.Visible = true;
                    imgNews.ImageUrl = DataBinder.Eval(e.Item.DataItem, "Image_Url").ToString();
                }


            }
        }
    }
}